<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  news
 */

class m_news_services_ItemService extends f_core_Service
{
	/**
	 * @var m_news_services_ItemService
	 */
	private static $instance;
	
	/**
	 * Constructor
	 */
	private function __construct()
	{
		// Code if needed...
	}
	
	/**
	 * @return m_news_services_ItemService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self();
		}
		return self::$instance;
	}

    /**
     * Get all news with all informations
     *
     * @param <type> $news
     * @param <type> $page
     * @return <type> Array
     */
	public function getNewsArray($news, $page = null)
	{
        $newsTab = Array();
		
		if(is_array($news) && !empty($news))
		{
			/* @var $value m_news_documents_item */
			foreach($news as $key => $value)
			{
				if(!empty($value))
				{
                    $url = !is_null($page) ? m_website_services_PageService::getInstance()->getDynamicUrl($value, $page) : "#";
					$newsTab[$key] = Array("news" => $value, "url" => $url);
				}
			}
		}

        return $newsTab;
	}

    public function formatDateForInsert($dateStart, $dateEnd)
    {
        $dates = array();

        $dates["dateStart"] = !empty($dateStart) ? f_date_Date::getInstanceFromFormat($dateStart,"d/m/Y")->toString() : null;
        $dates["dateEnd"] = !empty($dateEnd) ? f_date_Date::getInstanceFromFormat($dateEnd,"d/m/Y")->toString() : null;

        return $dates;
    }
}